package routers

import (
	"gitee.com/kessil/chicory/internal/config"
	"gitee.com/kessil/chicory/internal/middleware"
	"gitee.com/kessil/chicory/internal/models"
	"gitee.com/kessil/chicory/internal/repositories"

	"github.com/go-chi/chi/v5"
	"xorm.io/xorm"
)

type DeskRouter struct {
	*GenericCRUDRouter[models.Desk]
	db   *xorm.Engine
	cfg  *config.Config
	repo *repositories.DeskRepository
}

func NewDeskRouter(db *xorm.Engine, cfg *config.Config) *DeskRouter {
	// 定义允许筛选的字段
	allowedFields := []string{"name"}

	// // 定义Patch忽略的字段
	// ignoreFields := []string{"id", "created", "updated", "deleted"}
	// 创建泛型CRUD路由器
	genericRouter := NewGenericCRUDRouter[models.Desk](db, cfg, "desk", allowedFields)

	return &DeskRouter{
		GenericCRUDRouter: genericRouter,
		db:                db,
		cfg:               cfg,
		repo:              repositories.NewDeskRepository(db),
	}
}

func (dr *DeskRouter) Routes() chi.Router {
	r := chi.NewRouter()

	// 使用JWT认证中间件
	r.Use(middleware.JWTAuthMiddleware(dr.cfg))

	// 继承泛型CRUD路由
	r.Mount("/", dr.GenericCRUDRouter.Routes())

	// 添加用户特有的路由

	return r
}
